package ui.dialog;

import java.util.ArrayList;

import javax.swing.table.AbstractTableModel;

import linkfinders.Link;

public class LinkFoundModel extends AbstractTableModel
{

	/**
	 * 
	 */
	private static final long serialVersionUID = 8601398028724653701L;
	private String[] cols;
	protected ArrayList<Link> links = new ArrayList<Link>();
	private ArrayList<Boolean> checked = new ArrayList<Boolean>();
	
	public LinkFoundModel(String[] cols,ArrayList<Link> arrayList)
	{
		this.cols = cols;
		this.links = arrayList;
		for(int i = 0; i < arrayList.size();i++)
			checked.add(false);
	}
	@Override
	public int getColumnCount()
	{
		return cols.length;
	}

	@Override
	public int getRowCount()
	{
		return links.size();
	}

	@Override
	public Object getValueAt(int arg0, int arg1)
	{
		Boolean checked = this.checked.get(arg0);
		String link = this.links.get(arg0).getUrl();
		if(arg1 == 0)
			return checked;
		else
			return link;
		
	}
	
	
	@Override
	public String getColumnName(int col)
	{
		return cols[col];
	}

	@SuppressWarnings({ "unchecked", "rawtypes" })
	@Override
	public Class getColumnClass(int col)
	{
		if(col == 0)
			return Boolean.class;
		else
			return String.class;
	}
	
	public boolean isChecked(int row)
	{
		return checked.get(row);
	}
	
	public void setChecked(int row,boolean b)
	{
		checked.set(row, b);
	}
	public String getLinkAt(int row)
	{
		return links.get(row).getUrl();
	}
}

